package com.day16;

/**
 * 使用线程安全重写单例懒汉模式
 */
public class BankTest {


}


class Bank {
    private Bank() {

    }

    private static Bank instancec = null;

    public static synchronized Bank getInstance() {
        if (instancec == null) {
            instancec = new Bank();
        }
        return instancec;
    }
}


class BankDemo {
    private BankDemo() {

    }

    private static BankDemo instancec = null;

    public static BankDemo getInstance() {
        //方式一:效率比较低
//        synchronized(BankDemo.class){
//            if(instancec == null){
//                instancec = new BankDemo();
//            }
//            return instancec;
//        }

        //方式二:
        if (instancec == null) {
            synchronized (Bank.class) {
                if (instancec == null) {
                    instancec = new BankDemo();
                }
                return instancec;
            }
        }
        return null;
    }
}